import { Injectable, Inject } from '@angular/core';
import { ActivatedRouteSnapshot } from '@angular/router';

import { NavTabService } from './nav-tab.service';
import { ROUTE_REUSE } from '../keys';


@Injectable({
  providedIn: 'root'
})
export class ReuseStrategyService<B> {

  constructor(private navTabService: NavTabService<B>, @Inject(ROUTE_REUSE) private routeReuse: boolean) { }

  shouldDetach(route: ActivatedRouteSnapshot): boolean {
    if (this.routeReuse) {
      return this.navTabService.shouldDetach(route);
    } else {
      return false;
    }
  }

  store(route: ActivatedRouteSnapshot, handle: {}): void {
    if (this.routeReuse) {
      this.navTabService.store(route, handle);
    } else {
      // ...
    }
  }

  shouldAttach(route: ActivatedRouteSnapshot): boolean {
    if (this.routeReuse) {
      return this.navTabService.shouldAttach(route);
    } else {
      return false;
    }
  }

  retrieve(route: ActivatedRouteSnapshot): {} {
    if (this.routeReuse) {
      return this.navTabService.retrieve(route);
    } else {
      return null;
    }
  }

  shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    if (this.routeReuse) {
      return this.navTabService.shouldReuseRoute(future, curr);
    } else {
      return future.routeConfig === curr.routeConfig;
    }
  }
}
